<script>
  import addtable from '@/mixins/addtable'
  import AjaxStore from '@/utils/store/proxyAjax'
  import store from './store.js'

  export default {
    name: 'parameter',
    mixins: [addtable, store],
    data() {
      return {
        selectedList: [],
        tableOptWidth: '100',
				dialogType: '',
        dialogAddTitle: '新增综合参数',
        dialogEditTitle: '编辑综合参数',
        dialogLookTitle: '查看综合参数',
        idKey: 'id',
        delIdKey: 'id',
        delListIdKey: 'ids',

        addUrl: '/v1/sys/parameter/add',
        updateUrl: '/v1/sys/parameter/update',
        delUrl: '/v1/sys/parameter/delete',
        delListUrl: '/v1/sys/parameter/deleteList',
        syncUrl: '/v1/sys/parameter/sync',
        url: '/v1/sys/parameter/findById',
        store: new AjaxStore({
          url: '/v1/sys/parameter/query'
        }),
        columns: [
           { prop: "code", label: "参数代码", sortable: true, width: "240", 'show-overflow-tooltip': true, 'header-align': 'center' },
           { prop: "codeName", label: "参数名称", sortable: true, width: "240", 'show-overflow-tooltip': true, 'header-align': 'center' },
           { prop: "codeValue", label: "参数值", sortable: true, width: "240", 'show-overflow-tooltip': true, 'header-align': 'center' },
           { prop: "remark", label: "备注", sortable: true, 'min-width': "240", 'show-overflow-tooltip': true, 'header-align': 'center' }
		    ],
        searchFields: [
          { label: '参数代码', prop: 'code', placeholder: '输入参数代码', anchor: 9 },
          { label: '参数名称', prop: 'codeName', placeholder: '输入参数名称', anchor: 12 }
		    ],
        searchModel: {
          "code": '',
          "codeName": ''
		    },
        searchBtnList: this.searchBtns,
        toolPanelBtnList: this.toolPanelBtns,
        tableRowBtnList: this.tableRowBtns,
        formPanel: {
          add: {
            model: {
           		"code": '',
           		"codeName": '',
           		"codeValue": '',
           		"remark": ''            },
            fields: [
        		{ label: '参数代码', prop: 'code', placeholder: '输入参数代码', anchor: 24},
        		{ label: '参数名称', prop: 'codeName', placeholder: '输入参数名称', anchor: 24},
        		{ label: '参数值', prop: 'codeValue', placeholder: '输入参数值', anchor: 24},
        		{ label: '备注', prop: 'remark', type: 'textarea', placeholder: '输入备注', anchor: 24}            ],
            rules: {
               "code": [{ required: true, message: '请输入参数代码', trigger: 'blur' }],
               "codeName": [{ required: true, message: '请输入参数名称', trigger: 'blur' }],
            },
            title: '新增信息',
            type: 'ADD',
            ref: 'addForm',
            submitBtnList: this.addBtns
          },
          edit: {
            model: {
             "projectId": '',
             "id": '',
          	 "code": '',
          	 "codeName": '',
          	 "codeValue": '',
          	 "remark": ''            },
            fields: [
       			 { label: '参数代码', prop: 'code', placeholder: '输入参数代码', anchor: 24},
       			 { label: '参数名称', prop: 'codeName', placeholder: '输入参数名称', anchor: 24},
       			 { label: '参数值', prop: 'codeValue', placeholder: '输入参数值', anchor: 24},
       			 { label: '备注', prop: 'remark', type: 'textarea', placeholder: '输入备注', anchor: 24}            ],
            rules: {
         	   "code": [{ required: true, message: '请输入参数代码', trigger: 'blur' }],
         	   "codeName": [{ required: true, message: '请输入参数名称', trigger: 'blur' }],
            },
            title: '编辑信息',
            type: 'EDIT',
            ref: 'editForm',
            submitBtnList: this.editBtns
          },
          look: {
            model: {
              "code": '',
              "codeName": '',
              "codeValue": '',
              "remark": ''
            },
            fields: [
          		{ label: '参数代码', prop: 'code', placeholder: '', anchor: 24, disabled: true },
          		{ label: '参数名称', prop: 'codeName', placeholder: '', anchor: 24, disabled: true },
          		{ label: '参数值', prop: 'codeValue', placeholder: '', anchor: 24, disabled: true },
          		{ label: '备注', prop: 'remark', type: 'textarea', placeholder: '', anchor: 24, disabled: true }            ],
            rules: {
            },
            title: '查看信息',
            type: 'LOOK',
            ref: 'lookForm',
            submitBtnList: this.lookBtns
          }
        }
      }
    },
    methods: {
      handleSync() {
        this.syncData().then((res) => {
          if (res.success) {
            this.$message({
              type: 'success',
              message: res.message
            })
          } else {
            this.$message({
              type: 'error',
              message: res.message
            })
          }
        }).catch((error) => {
          console.log(error)
        })
      }
    },
    beforeCreate () {
      // 根据页面路由找出有权限访问的 url 数组
      const urlArr = (this.$route.meta && this.$route.meta.children || []).map(item => item.url)

      this.searchBtns = [
        { label: '查询', methods: 'handleSearch', url: '/v1/sys/parameter/query', icon: 'el-icon-search', type: 'primary', disabled: false },
        { label: '重置', methods: 'handleSearchReset', url: '', icon: 'el-icon-refresh', type: 'warning', disabled: false }
      ].filter(item => (item.url && urlArr.includes(item.url)) || !item.url)

      this.toolPanelBtns = [
        { label: '新增', methods: 'handleAdd', url:'/v1/sys/parameter/add', icon: 'el-icon-circle-plus-outline', type: 'primary', disabled: false },
        { label: '删除', methods: 'handleDelGroup', url:'/v1/sys/parameter/deleteList', icon: 'el-icon-delete', type: 'danger', disabled: false },
        { label: '同步', methods: 'handleSync', url:'/v1/sys/parameter/sync', svgIcon: 'sync', type: 'sync', disabled: false }
      ].filter(item => (item.url && urlArr.includes(item.url)) || !item.url)

      this.tableRowBtns = [
        { label: '编辑', methods: 'handleEdit', url:'/v1/sys/parameter/update', icon: 'el-icon-edit-outline', type: 'primary', key: 'edit', align: 'top-start', disabled: false },
        { label: '删除', methods: 'handleDelete', url:'/v1/sys/parameter/delete', icon: 'el-icon-delete', type: 'danger', key: 'delete', align: 'top-start', disabled: false }
      ] .filter(item => (item.url && urlArr.includes(item.url)) || !item.url)

      this.addBtns = [
        { label: '保存并新增', methods: 'handleSubmitAndAdd', url:'/v1/sys/parameter/add', icon: 'el-icon-circle-check-outline', type: 'primary', disabled: false },
        { label: '保存', methods: 'handleAddSubmit', url:'/v1/sys/parameter/add', icon: 'el-icon-circle-check-outline', type: 'primary', disabled: false },
        { label: '取消', methods: 'handleCancel', url:'',icon: 'el-icon-circle-close-outline', disabled: false }
      ].filter(item => (item.url && urlArr.includes(item.url)) || !item.url)

      this.editBtns = [
        { label: '保存', methods: 'handleEditSubmit', url:'/v1/sys/parameter/update', icon: 'el-icon-circle-check-outline', type: 'primary', disabled: false },
        { label: '取消', methods: 'handleCancel', url:'', icon: 'el-icon-circle-close-outline', disabled: false }
      ].filter(item => (item.url && urlArr.includes(item.url)) || !item.url)

      this.lookBtns = [
        { label: '保存', methods: '', url:'', icon: 'el-icon-circle-check-outline', type: 'primary', disabled: true },
        { label: '取消', methods: 'handleCancel', url:'', icon: 'el-icon-circle-close-outline', disabled: false }
      ].filter(item => (item.url && urlArr.includes(item.url)) || !item.url)
    }
  }
</script>

<style lang="scss">
  .parameter{
    .searchPanel{
      padding-bottom: 0;
      .search-btn-box{
        bottom: 0;
      }
    }
  }
</style>
